<?php
declare (strict_types = 1);

namespace app\admin\middleware;

use think\facade\Session;

class CheckLogin
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        
        if($request->baseUrl()!="/admin/index/login"&&!Session::has("username")){
            return redirect("/admin/index/login");
        }
        if($request->baseUrl()=="/admin/index/login"&&Session::has("username")){
            return redirect("/admin");
        }
        return $next($request);
    }
}
